<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>添加编辑合班</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="110px" ref="editForm">
          <el-form-item label="选择合并班级：" prop="remark">
            <div>
              <component
                  v-bind:is="item.propertyType"
                  :property.sync="item"
                  v-for="(item, index) in getPower"
                  :key="index"
                  @updateVal="updateValone"
              ></component>
            </div>
            <div>
              <component
                  v-bind:is="item.propertyType"
                  :property.sync="item"
                  v-for="(item, index) in getPower"
                  :key="index"
                  @updateVal="updateValtwo"
              ></component>
            </div>
          </el-form-item>
          <el-form-item label="备注：" prop="remark">
            <el-input v-model="remark"
                      placeholder="备注"
                      size="small"
                      type="textarea"
                      maxlength="200"
                      :autosize="{
               minRows: 2, maxRows: 4
                      }"
                      show-word-limit></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {classJoinAdd} from '@/api/admin/class'
export default {
  props: ['visible', 'noteId'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      searchFormOne: {
        class_id: '',
        section_id: '',
      },
      searchFormTwo: {
        class_id: '',
        section_id: '',
      },
      remark: '',
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '年段', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      }
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
    }
  },
  created() {

  },
  methods: {
    checkEditFn() {
      console.log('提交的参数：, ', this.searchFormOne, this.searchFormTwo)
      if(!this.searchFormOne.class_id && !this.searchFormTwo.class_id){
        this.$message.error('请选择需要合并的两个班级')
        return
      }
      let class_list = [this.searchFormOne.class_id, this.searchFormTwo.class_id]
      classJoinAdd({class_ids: class_list.join(','), remark: this.remark}).then(res=>{
        console.log(res)
        if(!res.code){
          this.$message.success('添加成功')
          this.$emit('InitFn')
          this.closePOpup()
        }else{
          this.$message.error(res.msg)
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 更新值
    updateValone(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.searchFormOne[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.searchFormOne[option.select[i].name] = option.select[i].valueText
          } else {
            this.searchFormOne[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
    updateValtwo(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.searchFormTwo[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.searchFormTwo[option.select[i].name] = option.select[i].valueText
          } else {
            this.searchFormTwo[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 500px;
  height: 350px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.jobTime span {
  padding: 0 10px;
}
</style>


